package com.ruowei.modules.sys.repository.entity;

import com.ruowei.common.repository.BaseRepository;
import com.ruowei.modules.sys.domain.entity.QSysEmployee;
import com.ruowei.modules.sys.domain.entity.SysEmployee;
import com.ruowei.modules.sys.domain.enumeration.EmployeeStatusType;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;


/**
 * Spring Data  repository for the SysEmployee entity.
 */
@SuppressWarnings("unused")
@Repository
public interface SysEmployeeRepository
        extends BaseRepository<Long, SysEmployee, QSysEmployee> {

    Optional<SysEmployee> findFirstByOfficeNameAndEmpName(String officeName, String empName);

    List<SysEmployee> findAllByEmpNameContainsAndDeletedIsFalseAndStatusOrderByEmpNameAsc(String empName, EmployeeStatusType status);

    List<SysEmployee> findAllByOfficeIdInAndDeletedIsFalseAndStatus(List<Long> officeIds, EmployeeStatusType status);

    List<SysEmployee> findAllByPersonnelIdIn(List<Long> personnelIds);

    void deleteAllByIdIn(List<Long> ids);

    Optional<SysEmployee> findOneByPersonnelId(Long personnelId);

    @Modifying
    @Query("update SysEmployee set office.id = ?2, officeName = ?3 where personnelId = ?1")
    void updateOffice(Long personnelId, Long officeId, String officeName);
}
